# -*- coding: UTF-8 -*- 
#习题16：读写文件
#close 关闭文件
#read 读取文件内容
#readline 读取文本中的一行
#truncate 清空文件，小心使用
#write 写入文件

from sys import argv;
script, filename =argv;

print ("We're going to erase %r." % filename);#打印文件信息
print ("If you don't want that, hit CTRL-C (^C).");
print ("If you do want that, hit RETURN.");

input ("?");

print ("Opening the file...");
target = open (filename,'w');#写入文件

print ("Truncating the file. Goodbye");
target.truncate();#清空文件

print ("Now I'm going to ask you for three lines.");
line1 = input ("line 1: ");#录入内容
line2 = input ("line 2: ");#录入内容
line3 = input ("line 3: ");#录入内容

print ("I'm going to write these to the file.");

target.write (line1);#写入内容
target.write ("\n");#打印换行
target.write (line2);#写入内容
target.write ("\n");#打印换行
target.write (line3);#写入内容
target.write ("\n");#打印换行

target.write("line1:%s\nline2:%s\nline3:%s\n" % (line1,line2,line3));